package com.ybc.chinese.utils;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.ybc.chinese.R;

/**
 * 进度框
 */
public class DialogUtil {

    public static ProgressDialog getProgressDialog(Context context, int resId) {
        return getProgressDialog(context, context.getResources().getString(resId));
    }

    public static ProgressDialog getProgressDialog(Context context, String res) {
        ProgressDialog mPd = null;
        mPd = new ProgressDialog(context);
        mPd.setCancelable(true);
        /*mPd.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                // 屏蔽Search键(因为按搜索按键会被关闭)
                switch (event.getKeyCode()) {
                    case KeyEvent.KEYCODE_SEARCH:
                        return true;
                    case KeyEvent.KEYCODE_BACK:
                        // cancelTask();
                        // cancelConfirm();
                        return true;
                    default:
                        return false;
                }
            }
        });*/
        mPd.setMessage(res);
        return mPd;
    }

    public static Dialog getCustomerDialog(Context ctx, String message, String confirmText, String cancelText, View.OnClickListener confirmListener, View.OnClickListener cancelListener) {
        Dialog dialog = new Dialog(ctx);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        //dialog.setCancelable(false);
        dialog.setContentView(R.layout.dialog_customer);
        TextView tvMessage = (TextView) dialog.findViewById(R.id.tv_message);
        tvMessage.setText(message);
        TextView tvCancel = (TextView) dialog.findViewById(R.id.tv_cancel);
        TextView tvConfirm = (TextView) dialog.findViewById(R.id.tv_confirm);
        tvConfirm.setText(confirmText);
        tvCancel.setText(cancelText);
        tvCancel.setOnClickListener(cancelListener);
        tvConfirm.setOnClickListener(confirmListener);
        return dialog;
    }
}
